package server.session.handler;

import server.session.UserSession;
import unit.request.CreateNewUserRequest;
import unit.request.Request;
import unit.response.CreateNewUserRequestResponse;
import unit.response.Response;

import java.io.IOException;

/**
 * @author Yuri Denison
 * @since 08.08.11
 */
public class CreateNewUserRequestHandler implements RequestHandler {
    @Override
    public void handleRequest(Request request, UserSession userSession) {
        CreateNewUserRequest createNewUserRequest = (CreateNewUserRequest) request;
        int id = userSession.getDataStorage().addNewUser(createNewUserRequest.getLogin(), createNewUserRequest.getPassword());
        Response response = new CreateNewUserRequestResponse(createNewUserRequest.getRequestID(), userSession.getSession(), id);
        try {
            userSession.getConnector().send(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

